package io.le.starter.lock.locker.manager;

import io.etcd.jetcd.Client;
import io.le.starter.lock.locker.AbstractLock;
import io.le.starter.lock.locker.EtcdLock;
import io.le.starter.lock.locker.RedisLock;
import io.le.starter.lock.locker.ZookeeperLock;
import org.apache.zookeeper.ZooKeeper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * createTime：2025-04-07 15:44
 * description：锁工厂
 */
@Component
public class LockFactory {

    @Autowired
    public ZooKeeper zooKeeper;

    @Autowired
    public Client etcdClient;

    public static final String REDIS = "redis";

    public static final String ZOOKEEPER = "zookeeper";

    public static final String ETCD = "etcd";


    public AbstractLock getLock(String lockType, String lockName) {
        switch (lockType) {
            case REDIS:
                new RedisLock();

            case ZOOKEEPER:
                new ZookeeperLock(zooKeeper, lockName);

            case ETCD:
                new EtcdLock(etcdClient, lockName);
            default:
                return null;
        }
    }


}
